from google.appengine.ext import db
from domain import discussion
from domain import article
from domain import document

class Topic(db.Model):

    discussion = db.Reference(discussion.Discussion)
    article = db.Reference(article.Article)
    document = db.Reference(document.Document)
    type = db.StringProperty(required=True)
    title = db.StringProperty(required=True)
    createdate = db.DateTimeProperty(auto_now_add=True)
    updatedate = db.DateTimeProperty(auto_now=True)
    message = db.TextProperty(required=True)
    enabled = db.BooleanProperty(True)
    commentcount = db.IntegerProperty(default=0)
    user = db.UserProperty(required=True)
    nickname = db.StringProperty(required=True)

    def getAllowedTypes(self):
        return ['Article', 'Document', 'Discussion']

    def getKey(self):
        return self.key()

    def isValid(self):
        if (len(self.title) > 200):
            return False
        if (len(self.message) > 4000):
            return False
        return True

